/**
 * vue 的实例方法
 */
import Vue from 'vue'
const STORAGE = {
  install(Vue) {
    Vue.prototype.$localStorage = this;
    Vue.localStorage = this;
  },
  getItem(key) {
    return JSON.parse(window.localStorage.getItem(key))
  },
  setItem(key, value) {
    window.localStorage.setItem(key, JSON.stringify(value))
  },
  removeItem(key) {
    window.localStorage.removeItem(key)
  },
  clearData() {
    window.localStorage.clear();
  },
  getUsedSpace() {
    let size = 0;
    for (let item in window.localStorage) {
      if (window.localStorage.hasOwnProperty(item)) {
        size += window.localStorage.getItem(item).length
      }
    }
    //  kb
    return (size / 1024).toFixed(2)
  }
}
Vue.use(STORAGE)
